package com.sftz.modules.minapp.personNotice.module;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import com.sftz.modules.minapp.personNotice.form.NoticeForm;
import com.sftz.modules.minapp.personNotice.form.PersonNoticeForm;
import com.sftz.modules.minapp.personNotice.service.PersonNoticeViewService;
import com.sftz.modules.minapp.user.cache.RedissionUserCache;

@IocBean
@At("/wx/personNotice")
public class PersonNoticeModule {

	private static final Log log = Logs.get();
	@Inject
	private PersonNoticeViewService personNoticeViewService;

	/**
	 * 进入个人公告页页
	 */
	@At
	@Ok("json")
	public Object listJson(@Param("..") final PersonNoticeForm form, @Param("..") final NoticeForm formn) {
		String token = formn.getToken();
		Integer userId = RedissionUserCache.getUserId(token);

		return personNoticeViewService.findPersonNoticeList(form, userId);
	}

	/**
	 * 进入个人公告详情
	 */
	@At
	@Ok("json")
	public Object noticeDetails(@Param("noticeId") final Integer noticeId) {

		return personNoticeViewService.fetchInfo(noticeId);
	}

	/*
	 * 
	 * 点击单个标记已读
	 * 
	 * */

	@At
	@Ok("json")
	public Object fetchInfoAndUpdateRead(@Param("id") final Integer id, @Param("..") final NoticeForm formn) {
		String token = formn.getToken();
		Integer userId = RedissionUserCache.getUserId(token);

		return personNoticeViewService.fetchInfoAndUpdateRead(id, userId);
	}

	/*
	 * 
	 * 左滑，点击删除公告
	 * 
	 * */

	@At
	@Ok("json")
	public Object delUserNoticeById(@Param("..") final PersonNoticeForm form, @Param("..") final NoticeForm formn,
			@Param("noticeId") final Integer noticeId) {
		String token = formn.getToken();
		Integer userId = RedissionUserCache.getUserId(token);

		return personNoticeViewService.delUserNoticeById(form, noticeId, userId);
	}
}